using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using DTO;
using BUS;
using DAL;
using Utility;

public partial class Admin_nhanvienlist : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            LoadData();
        }
        if (Session["UserName"] == "")
        {
            Response.Redirect("dangnhap.aspx");
        }
        if (Session["ChucVu"].ToString() != "1")
        {
            Response.Redirect("dangnhap.aspx");
        }
    }
    private void LoadData()
    {
        Criteria cri = new Criteria();
        if (txt_tennv.Text != "")
            cri.add(Condition.AND, tbnhanviencolumn.Tennv, Condition.LIKE, txt_tennv.Text);
        int total = 0;
        tbnhanviencollection nhanviencollection =
            tbnhanvienBUS.GET(cri.Criter, 0, 1, tbnhanviencolumn.Manv.ToString(), OrderDirection.ASC.ToString(), out total);
       
        Repeater1.DataSource = nhanviencollection;

        Repeater1.DataBind();

    }
    protected void btn_Timkiem_Click(object sender, EventArgs e)
    {
        LoadData();
    }
    protected void btn_xoa_Click(object sender, EventArgs e)
    {
        foreach (RepeaterItem item in this.Repeater1.Items)
        {
            CheckBox cb = (CheckBox)item.FindControl("cb_xoa");
            if (cb.Checked == true)
            {
                // xoa

                HiddenField hf_id = (HiddenField)item.FindControl("hf_id");
                tbnhanvienBUS.Delete(int.Parse(hf_id.Value));
            }
        }
        LoadData();
    }
    protected void Repeater1_ItemDataBound(object sender, RepeaterItemEventArgs e)
    {
        if (e.Item.ItemType == ListItemType.AlternatingItem ||
           e.Item.ItemType == ListItemType.Item)
        {
            tbnhanvienDTO nhanvien = (tbnhanvienDTO)e.Item.DataItem;

            HyperLink hyp_ten = (HyperLink)e.Item.FindControl("hyp_ten");
            HyperLink h = (HyperLink)e.Item.FindControl("hyp_Sua");
            //h.NavigateUrl = "~/Admin/suanv.aspx?id=" + (khachhang.Makh.ToString());
            Literal lit_ma = (Literal)e.Item.FindControl("lit_ma");

            HiddenField hf_id = (HiddenField)e.Item.FindControl("hf_id");
            hf_id.Value = nhanvien.Manv.ToString();
            lit_ma.Text = nhanvien.Manv.ToString();

            hyp_ten.NavigateUrl = "~/Admin/nhanvienct.aspx?id=" + nhanvien.Manv.ToString();
            hyp_ten.Text = nhanvien.Tennv.ToString();

            HyperLink hyp_sua = (HyperLink)e.Item.FindControl("hpl_Edit");
            hyp_sua.NavigateUrl = "~/Admin/nhanviensua.aspx?id=" + nhanvien.Manv.ToString();

            tbchucvuDTO chucvudto = tbchucvuBUS.GetByID(nhanvien.Machucvu);
            if (chucvudto != null)
            {
                Label lb_chucvu = (Label)e.Item.FindControl("lb_cv");
                lb_chucvu.Text = chucvudto.Tenchucvu.ToString();
            }
        }
    }
    protected void btn_them_Click(object sender, EventArgs e)
    {
        Response.Redirect("nhanvienthem.aspx");
    }
}
